package com.xqls.server.netty;

import com.xqls.server.dto.FluSoketCommonDto;
import com.xqls.server.dto.SoketCommonDto;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.CorruptedFrameException;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.TooLongFrameException;
import io.netty.util.ReferenceCountUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.ByteOrder;
import java.util.List;

/**
 * Created by hdg on 2017/7/11.
 */
public class FluCommonDecoder extends ChannelInboundHandlerAdapter {
    private static final Logger LOG = LoggerFactory
            .getLogger(FluCommonDecoder.class);



    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf in=(ByteBuf)msg;
        FluSoketCommonDto commonDto=FluSoketCommonDto.getDecode(in);
        in.discardReadBytes();
        if(commonDto==null){
            LOG.error("解析协议异常");
        }

        ctx.fireChannelRead(commonDto);
        ReferenceCountUtil.release(in);
    }


}
